#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
#  
#  
# Licensed Materials - Property of IBM 
#  
# (C) COPYRIGHT International Business Machines Corp. 2000,2002 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 

# "@(#)10   1.9   src/rsct/rm/ER/logevent, ERrm, rsct_rori, roris01a 3/11/02 16:03:45";

#####################################################################
#
# Name:    logevent
#
# Purpose: Logs event information generated by Event Response resource
#          manager to a specified log file.
#
# Inputs:  Name of the file where event information is logged.
#          An absolute path for the logfile operand should be specified.  
#
#####################################################################

generate_message () {

        cat  <<EOF
=====================================

${EventTime}

${ConditionName}: $ERRM_COND_NAME
${Severity}: $ERRM_COND_SEVERITY
${EventType}: $ERRM_TYPE
${Expression}: $ERRM_EXPR

${ResourceName}: $ERRM_RSRC_NAME 
${ResourceClass}: $ERRM_RSRC_CLASS_NAME
${DataType}: $ERRM_DATA_TYPE
${DataValue}: $ERRM_VALUE
${NodeName}: $ERRM_NODE_NAME
${NodeNameList}: $ERRM_NODE_NAMELIST
${RsrcType}: $ERRM_RSRC_TYPE
EOF
        
}

# main()

PERL=/usr/sbin/rsct/perl5/bin/perl

CTMSG=/usr/sbin/rsct/bin/ctdspmsg
MSGMAPPATH=/usr/sbin/rsct/msgmaps
export MSGMAPPATH


ConditionName=`$CTMSG script IBM.ERrm.cat MSG_SH_COND_NAME`
Severity=`$CTMSG script IBM.ERrm.cat MSG_SH_SEVERITY`
EventType=`$CTMSG script IBM.ERrm.cat MSG_SH_DATA_TYPE`
Expression=`$CTMSG script IBM.ERrm.cat MSG_SH_EXPRESSION`

ResourceName=`$CTMSG script IBM.ERrm.cat MSG_SH_RES_NAME`
ResourceClass=`$CTMSG script IBM.ERrm.cat MSG_SH_RES_CLASS`
DataType=`$CTMSG script IBM.ERrm.cat MSG_SH_DATA_TYPE`
DataValue=`$CTMSG script IBM.ERrm.cat MSG_SH_DATA_VALUE`
NodeName=`$CTMSG script IBM.ERrm.cat MSG_SH_NODE_NAME`
NodeNameList=`$CTMSG script IBM.ERrm.cat MSG_SH_NODE_NAMELIST`
RsrcType=`$CTMSG script IBM.ERrm.cat MSG_SH_RSRC_TYPE`
Usage=`$CTMSG script IBM.ERrm.cat MSG_SH_USAGE`
InvalidDir=`$CTMSG script IBM.ERrm.cat MSG_SH_INVALID_DIR`


while getopts ":h" opt
do
  case $opt in

    h ) print "${Usage} : `basename $0` [-h] logfile "
        exit 0;;

    ? ) print "${Usage} : `basename $0` [-h] logfile "
        exit 3;;
  esac
done



# Check if a required logfile is specified
if [[ $# -lt 1 ]]; then
   print -u2 "${Usage} : `basename $0` [-h] logfile "
   exit 1
fi

# Check if the logfile path is valid
fileName=$1
pathName=${fileName%/*}

if [[ -z $pathName ]]; then
   pathName=/
fi

if [[ ! -d $pathName ]]; then
   print -u2 "${InvalidDir} "
   exit 2
fi

# convert time string
seconds=${ERRM_TIME%,*}

EventTime=$(seconds=$seconds $PERL -e \
'
use POSIX qw(strftime);
print strftime("%A %D %T", localtime($ENV{seconds}) );  

'
)

# alog only exists on aix, bmp, 2/23/01
uname=`uname`
if [ "$uname" = "AIX" ]
then
  generate_message | alog -q -f $1 -s 65536
else
  generate_message >> $1
fi
